<?php

namespace app\controller\Request;

use Exception;
use app\controller\Response\TradePayNotifyResponse;
use app\controller\Util\Signer;

class TradePayNotifyRequest extends AbstractRequest
{
    /**
     * @throws Exception
     */
    public function getData()
    {
        $params = $this->getParams();

        $signer = new Signer();
        $signer->setKey($this->getHwPublicKey());
        $signer->setParams($this->getParams());

        if (! $signer->verify($this->getSign())) {
            throw new Exception('签名错误');
        }

        return $params;
    }

    public function sendData($data): TradePayNotifyResponse
    {
        return $this->response = new TradePayNotifyResponse($this, $data);
    }
}
